package com.csx.micrometer.demo.consumer.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author cuisongxu
 * @date 2022/12/3 23:40
 */
@RestController
@RequestMapping("/consumer/resttemplate")
public class DemoConsumerRestTemplateController {

    @Resource(name = "restTemplate")
    private RestTemplate restTemplate;

    @Resource(name = "restTemplateLoadBalancer")
    private RestTemplate restTemplateLoadBalancer;

    @GetMapping("/testRestTemplate")
    public String testRestTemplate() {
        String username = restTemplate.getForObject("http://localhost:8012/provider/getUsername", String.class);
        return "hello restTemplate " + username;
    }

    @GetMapping("/testLoadBalance")
    public String testLoadBalancer() {
        String username = restTemplateLoadBalancer.getForObject("http://demo-micrometer-provider/provider/getUsername", String.class);
        return "hello loadbalancer " + username;
    }
}
